<?php

/**
 * Controller for patient detail pages including edit demographic info,
 * check-in a department, input medicine, service,...
 * 
 * @package core.controllers
 * @author ptnguyen
 * @version $Id:$
 * @copyright 2009 LHV Company
 */
class C_ResidentPatient extends Controller {
	
	var $logger;
	var $template_mod;
	
    public function C_ResidentPatient($template_mod = "general") {
        parent::Controller();
        $this->logger = &LoggerManager::getLogger('core.controllers.C_ResidentPatient');
        if (Celini::getCurrentController() == 'ResidentPatient') {
            $menu =& Menu::getInstance();
            $menu->currentSection = 'patient';
        }
        $this->template_mod = $template_mod;        
        $this->view->path = 'resident_patient';
    }
    

    
    public function actionDisplayInputForm() {
    	$patientId = $_GET['patientId'];    	
    	$this->assign('currentTicketTree', $this->buildCurrentTicketTree($patientId));
    	
    	$ticketId = Celini::newORDO('Ticket')->getLastTicketId($patientId);    	
    	$this->assign('currentTicketId', $ticketId);    	    	
    	return $this->view->render('display_input_form.html');
    }
    
    public function actionGetInputFormBody() {
    	$ticketId = $_GET['ticketId'];
    	$this->assign('currentTicketId', $ticketId);
    	return $this->view->render('input_form_body.html');
    }
    
    private function buildCurrentTicketTree($patientId) {
    	$ticketResult = Celini::newORDO('Ticket')->getAllTicketOfPatient($patientId, true);
    	$ticketTree = array();
    	foreach ($ticketResult as $ticket) {
    		$ticketTree[$ticket['ticket_id']] = Celini::newORDO('Department', $ticket['department_id'])->getLocalizedText('name');    		
    	}
    	return $ticketTree;
    }
}
?>